package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.bean.ModifyUser;
import com.kgc.scd.bean.User;
import com.kgc.scd.bean.UserVO;
import com.kgc.scd.service.UserServiceFeign;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author: WangKuoKuo
 * @create: 2022-06-14 16:06
 * @description:
 **/
@RestController
@Api(tags = "09、用户个人中心")
public class UserWebController  {
    @Autowired
    private UserServiceFeign userServiceFeign;

    @ApiOperation("修改用户密码")
    @RequestPermission
    @GetMapping("/modUserPwd")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pwd", value = "原密码"),
            @ApiImplicitParam(name = "newPwd", value = "新密码"),
            @ApiImplicitParam(name = "newAgainPwd", value = "确认密码"),
    })
    public RequestResult<String> modUserPwd(@RequestUser UserAnno userAnno,
                                          @RequestParam(required = false) String pwd,
                                          @RequestParam String newPwd,
                                          @RequestParam String newAgainPwd) {

        return userServiceFeign.modUserPwd(userAnno.getUserId(), pwd, newPwd, newAgainPwd);

    }


    @ApiOperation("查询个人中心")
    @PostMapping("/queryPersonCenterInfo")
    @RequestPermission
    public RequestResult<UserVO> queryPersonCenterInfo(@RequestUser UserAnno userAnno) {

        return userServiceFeign.queryPersonCenterInfo(userAnno.getUserId());
    }

    //@ApiOperation("修改个人中心")
    //@RequestPermission
    //@PostMapping("/modifyPersonCenterInfo")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "uName", value = "用户名"),
    //        @ApiImplicitParam(name = "uPhone", value = "用户手机号"),
    //        @ApiImplicitParam(name = "uBirth", value = "用户生日"),
    //        @ApiImplicitParam(name = "uEmail",value = "用户邮箱"),
    //        @ApiImplicitParam(name = "uSex", value = "用户性别"),
    //        @ApiImplicitParam(name = "uAddrId", value = "用户默认地址")
    //})
    //public RequestResult<String> modifyPersonCenterInfo(@RequestUser UserAnno userAnno,
    //                                                  @RequestParam(value = "uName",required = false) String uName,
    //                                                  @RequestParam(value = "uPhone",required = false) String uPhone,
    //                                                  @RequestParam(value = "uBirth",required = false) Date uBirth,
    //                                                  @RequestParam(value = "uEmail",required = false) String uEmail,
    //                                                  @RequestParam(value = "uSex",required = false) String uSex,
    //                                                  @RequestParam(value = "uAddrId",required = false) String uAddrId) {
    //
    //    return userServiceFeign.modifyPersonCenterInfo(userAnno.getUserId(), uName, uPhone, uBirth, uEmail, uSex, uAddrId);
    //}
    @ApiOperation("修改个人中心")
    @RequestPermission
    @PostMapping("/modifyPersonCenterInfo")
    @ApiImplicitParams({

    })
    public RequestResult<String> modifyPersonCenterInfo(@RequestUser UserAnno userAnno,
                                                        @RequestBody ModifyUser user) {
        User user1 = new User();
        BeanUtils.copyProperties(user,user1);
        System.out.println(user1);
        return userServiceFeign.modifyPersonCenterInfo(userAnno.getUserId(),user1);
    }


}
